package org.jeecg.modules.reserve.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.jeecg.modules.reserve.entity.SdxcReserveUser;
import org.jeecg.modules.reserve.mapper.SdxcReserveUserMapper;
import org.jeecg.modules.reserve.service.ISdxcReserveUserService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import java.util.UUID;

/**
 * @Description: 用户管理
 * @Author: jeecg-boot
 * @Date:   2020-09-15
 * @Version: V1.0
 */
@Service
public class SdxcReserveUserServiceImpl extends ServiceImpl<SdxcReserveUserMapper, SdxcReserveUser> implements ISdxcReserveUserService {
    /**
     * 根据用户微信唯一标识保存用户信息
     *
     * @param openid
     * @return
     */
    @Override
    public String saveByOpenId(String openid) {
        QueryWrapper queryWrapper = new QueryWrapper();
        queryWrapper.eq("openid",openid);

        // 判断该用户是否已有用户信息
        SdxcReserveUser save = getOne(queryWrapper);
        if(null == save) {
            SdxcReserveUser user = new SdxcReserveUser();
            user.setId(UUID.randomUUID().toString().replace("-",""));
            user.setOpenid(openid);
            user.setIsFinish(SdxcReserveUser.USER_INFO_FINISH_NO);
            // 新增预约用户
            save(user);
            return user.getId();
        }
        return save.getId();
    }
}
